<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        body {
            font-size: 20px;
        }
        .box {
            width: 600px;
            height: 40px;
            margin: 200px auto;
            position: relative;
        }
        #txt {
            width: 498px;
            height: 38px;
            border: 1px solid #eee;
            font-size: 20px;
        }
        #search {
            width: 100px;
            height: 40px;
        }
        #keywords {
            position: absolute;
            top: 40px;
            left: 0;
            background-color: rgb(12, 255, 24);
            list-style: none;
            width: 500px;;
        }
        li {
            line-height: 24px;
        }
    </style>
</head>
<body>
<div class="box">
    <div class="top">
        <input type="text" id="txt"/><input type="button" value="search" id="search"/>
    </div>
    <ul id="keywords"></ul>
</div>
<script src="common.js"></script>
<script>
    var keywords = ["王宝强","王宝强的经纪人","王宝强的老婆","林丹出轨门","林丹夺冠","123","1234","2341","林丹的生平","JavaScript","Java"];

    //1.获取元素
    var txt = document.getElementById("txt"); //获取文本框
    var ul1 = id("keywords");
    txt.onkeyup = function () {
        var txtSearch = txt.value;
        if (txtSearch = '') {
            ul1.innerHTML = '';
            return;
        }
        ul1.innerHTML = "";
        for (var i = 0; i < keywords.length; i++) {
            if (keywords[i].indexOf(txtSearch) != -1) {
                var newLi = document.createElement('li');
                setText(newLi,keywords[i]);
                ul1.appendChild(newLi);

            }
        }
    }

</script>
</body>
</html>